package linkedlist.test82;

import listbyorder.utils.ListNode;

/**
 * 删除排序链表中的重复元素 II
 * @author code_yc
 * @version 1.0
 * @date 2020/7/14 13:49
 */
public class Solution1 {

    public ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null) return head;
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        ListNode t = dummy;
        while (t.next != null && t.next.next != null) {
            if (t.next.val == t.next.next.val) {
                int n = t.next.val;
                ListNode c = t.next;
                while (c != null && c.val == n) {
                    c = c.next;
                }
                t.next = c;
            } else {
                t = t.next;
            }
        }
        return dummy.next;
    }
}
